function fillInput({ saasData, baseInfo }) {
  let iframeWindow;
  const {
    lastYearData, isYearReport, sheetType, sheet
  } = saasData;
  iframeWindow = $('#mainIframe')[0].contentWindow;
  let message = '填报成功';
  try {
    let inputData = saasData.data;
    if (sheet === 'sds') {
      inputData = delSdsData(inputData.openParams.inputData.data.profit, baseInfo.companyInfo.institutionCode);
    }

    if (isYearReport) {
      inputData = hackYearReportInput(inputData, lastYearData, sheet);
    }

    for (let key in inputData) {
      let value = Number.parseFloat(inputData[key]).toFixed(2) || '0.00';
      if (iframeWindow.$(`[name$="${key}"]`).length != 0) {
        iframeWindow.$(`[name$="${key}"]`).val(value).trigger('change');
      }
    }
  } catch (e) {
    message = '填报失败' + e;
  }

  // todo finally
  window.postMessage({
    event: 'fillInputDone',
    data: {
      message: message
    }
  }, '*');
}





function autoInputAccount({ companyInfo }) {
  companyInfo = companyInfo || {};
  $('.go_login').click();
  $('[name="username"]').val(companyInfo.nationalTaxAccount || companyInfo.nationalTaxId).trigger('change');
  $('input:password').val(companyInfo.nationalTaxPass).trigger('change');
}

/**
 * 从页面获取公司信息
 */
function getNationData(taxType) {
  let institutionCode = window.baseInfoCache.companyInfo.institutionCode === "1" ? '2007' : "2013"
  let taxInfo = {
    institution: institutionCode, // 国税对应制度 2007 | 2013
    nsrsbh: '', // 纳税人申报号
    nsrmc: '', // 纳税人名称（纳税公司）
    skssqq: '', // 税款所属期起
    skssqz: '',// 税款所属期止
    isHsqjSmall: institutionCode === '2013',
    saasInstitution: ''
  };
  if (['balance', 'profit', 'cash'].includes(taxType)) {
    
    // if (inputTest.includes('未执行新金融准则')) {
    //   taxInfo.saasInstitution = 1;
    // }
    // if (taxType === cash && inputTest.includes('执行企业会计准则')) {
    //   taxInfo.saasInstitution = 1;
    // }
    // if (inputTest.includes('执行小企业会计准则')) {
    //   taxInfo.saasInstitution = 2;
    // }
  }

  window.postMessage({
    event: 'backNationData',
    data: {
      taxInfo: taxInfo
    }
  }, '*');
}

export {
  autoInputAccount,
  getNationData
}